﻿using FolderTag.Model;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace FolderTag.FolderView
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    public partial class TagListIemControl : UserControl
    {
        public TagListIemControl()
        {
            InitializeComponent();
        }

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            if (e.Property.Name == "DataContext") {

                if (StackPanel != null)
                {
                    StackPanel.Children.Clear();
                    List<TagItem> tagItems = e.NewValue as List<TagItem>;
                    if (tagItems != null && tagItems.Count > 0)
                    {
                        foreach (var tag in tagItems)
                        {
                            TagButton button = new TagButton();
                            button.DataContext = TagItem.Clone(tag);
                            StackPanel.Children.Add(button);
                        }
                    }
                }
            }
            base.OnPropertyChanged(e);
        }
    }
}
